package logic

import (
	"context"
	"home-mgr/model"

	"home-mgr/homerpc/homerpc"
	"home-mgr/homerpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PreShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPreShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PreShowLogic {
	return &PreShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PreShowLogic) PreShow(in *homerpc.PreShowRequest) (*homerpc.PreShowResponse, error) {
	// todo: add your logic here and delete this line

	var pres model.PreUser
	model.DB.Debug().Model(model.Pre{}).
		Select("pres.*, users.name as user_name, houses.address as house_address").
		Joins("left join houses on houses.id = pres.house_id").
		Joins("left join users on users.id = houses.user_id").
		First(&pres)
	return &homerpc.PreShowResponse{
		UserId:  int64(pres.UserId),
		HouseId: int64(pres.HouseId),
		Status:  pres.Status,
		Time:    pres.Time,
	}, nil
}
